Starting a Task from Scratch

How to start a task without first having save a context.

Initial configuration of the stack

  • Primes the pump
  • sets the stage for starting a task by jumping in as though the task had been interrupted earlier.
  • what goes in the control block
  • what goes in the stack
  • what would you put there to make of you were going to restore and run from it?
int initialize_stack(int* stack, void* task_address)
{
    // Calculate the top of the stack.
    int *stkptr = (int*)(stack + STACKSIZE - 1);

    *(stkptr)   = (int)task_address;   // PC
    *(--stkptr) = (int)0x0e0e0e0e;     // R14 - LR
    *(--stkptr) = (int)0x0c0c0c0c;     // R12
    *(--stkptr) = (int)0x0b0b0b0b;     // R11
    *(--stkptr) = (int)0x0a0a0a0a;     // R10
    *(--stkptr) = (int)0x09090909;     // R9
    *(--stkptr) = (int)0x08080808;     // R8
    *(--stkptr) = (int)0x07070707;     // R7
    *(--stkptr) = (int)0x06060606;     // R6
    *(--stkptr) = (int)0x05050505;     // R5
    *(--stkptr) = (int)0x04040404;     // R4
    *(--stkptr) = (int)0x03030303;     // R3
    *(--stkptr) = (int)0x02020202;     // R2
    *(--stkptr) = (int)0x01010101;     // R1
    *(--stkptr) = (int)0x00000000;     // R0
    *(--stkptr) = ARM_SVC_MODE_ARM;    // CPSR

    return (int)(stkptr);
}